//
//  ViewController.m
//  KnowledgeHierarchy
//
//  Created by linyi on 2020/4/6.
//  Copyright © 2020年 linyi. All rights reserved.
//


#import "RuntimeViewController.h"
#import "Person.h"
#import "NSObject+KVO.h"
@interface RuntimeViewController ()
@property (nonatomic, strong) Person *linyi;
@end

@implementation RuntimeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _linyi = [Person new];
    [_linyi LY_addObserver:self forKeyPath:@"pnames" options:NSKeyValueObservingOptionNew context:nil];
    
    
}

// 自定义kvo
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    NSLog(@"自定义KVO来到了这里%@",change);
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    static int i = 1;
    NSString *name = [NSString stringWithFormat:@"林一 %d",i++];
    [_linyi willChangeValueForKey:name];
    _linyi.pnames = name;
    [_linyi.pnames didChangeValueForKey:name];
}


@end
